﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IFServerDLL.DB;

namespace IFClientDLL.MyCalc.Data.Line
{
    public class MyData_Line_Minute : MyData_ListTicks
    {
        public MyData_Line_Minute(MyData_IF data, MyData_Line_Minute prevData):base(data)
        {
            _preLine =prevData ;
           
            MyData_Line_Minute line=this;
            while (true)
            {
                if (line == null)
                    break;
                _listAllLine.Add(line);
                line = line.PreLine;
            }
            _MinuteTime = new DateTime(data.MarketTime.Year, data.MarketTime.Month, data.MarketTime.Day, data.MarketTime.Hour, data.MarketTime.Minute, 0);

            AddData(data);
        }
        public override void AddData(MyData_IF data)
        {
            base.AddData(data);
            if (_listAllLine.Count > 0)
            {
                _AvgPrice = _listAllLine.Average(p => p.ClosePrice);
            }
            else
            {
                _AvgPrice = data.AvgPrice;
            }
        }
        private DateTime _MinuteTime;
        public DateTime MinuteTime { get { return _MinuteTime; } }
        
        private List<MyData_Line_Minute> _listAllLine=new List<MyData_Line_Minute>();
        public List<MyData_Line_Minute> ListAllLine { get { return _listAllLine; } }
        private MyData_Line_Minute _preLine;
        public MyData_Line_Minute PreLine { get { return _preLine; } }
        private decimal _AvgPrice;
        public decimal AvgPrice { get { return _AvgPrice; } }
       
    }
}
